package com.xmtlxx.web.controller.api;

import cn.hutool.core.bean.BeanUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.getui.push.v2.sdk.common.ApiResult;
import com.xmtlxx.common.annotation.Log;
import com.xmtlxx.common.config.TengboProperties;
import com.xmtlxx.common.core.controller.BaseController;
import com.xmtlxx.common.core.domain.PageQuery;
import com.xmtlxx.common.core.domain.R;
import com.xmtlxx.common.core.domain.entity.SysDept;
import com.xmtlxx.common.core.domain.entity.SysDictData;
import com.xmtlxx.common.core.page.TableDataInfo;
import com.xmtlxx.common.enums.BusinessType;
import com.xmtlxx.common.exception.ServiceException;
import com.xmtlxx.common.sms.aliyun.AliyunSmsService;
import com.xmtlxx.common.tengbo.PushDatasUtil;
import com.xmtlxx.common.tengbo.vo.*;
import com.xmtlxx.common.utils.BigDecimalUtils;
import com.xmtlxx.common.utils.DateUtils;
import com.xmtlxx.common.utils.JsonUtils;
import com.xmtlxx.common.utils.StringUtils;
import com.xmtlxx.common.wxap.util.HttpInvokerUtils;
import com.xmtlxx.oms.domain.Staging;
import com.xmtlxx.oms.domain.Task;
import com.xmtlxx.oms.domain.TaskDisposalInfo;
import com.xmtlxx.oms.domain.TaskDtl;
import com.xmtlxx.oms.domain.bo.*;
import com.xmtlxx.oms.domain.vo.*;
import com.xmtlxx.oms.mapper.TaskDisposalInfoMapper;
import com.xmtlxx.oms.mapper.TaskDtlMapper;
import com.xmtlxx.oms.mapper.TaskMapper;
import com.xmtlxx.oms.service.IBiService;
import com.xmtlxx.oms.service.IClassifyService;
import com.xmtlxx.oms.service.IOperatorLogService;
import com.xmtlxx.oms.service.ITaskDtlService;
import com.xmtlxx.system.domain.SysOss;
import com.xmtlxx.system.domain.bo.SysOssBo;
import com.xmtlxx.system.domain.vo.SysOssConfigVo;
import com.xmtlxx.system.service.ISysDeptService;
import com.xmtlxx.system.service.ISysDictDataService;
import com.xmtlxx.system.service.ISysOssConfigService;
import com.xmtlxx.system.service.ISysOssService;
import com.xmtlxx.tms.domain.Order;
import com.xmtlxx.tms.domain.bo.OrderBo;
import com.xmtlxx.tms.domain.vo.OrderVo;
import com.xmtlxx.tms.mapper.OrderMapper;
import com.xmtlxx.web.controller.center.service.ICenterService;
import com.xmtlxx.web.controller.center.service.ICommonService;
import com.xmtlxx.web.controller.center.vo.SendTaskVo;
import com.xmtlxx.web.controller.oms.service.IPropertyLogService;
import com.xmtlxx.web.controller.oms.service.IPropertyService;
import com.xmtlxx.web.controller.oms.service.IStagingService;
import com.xmtlxx.web.controller.oms.service.ITaskService;
import com.xmtlxx.web.controller.tms.service.IOrderService;
import com.xmtlxx.web.controller.wms.service.*;
import com.xmtlxx.wms.domain.CabinetGroup;
import com.xmtlxx.wms.domain.ExWarehouse;
import com.xmtlxx.wms.domain.bo.*;
import com.xmtlxx.wms.domain.vo.PutTaskVo;
import com.xmtlxx.wms.domain.vo.*;
import com.xmtlxx.wms.mapper.ExWarehouseMapper;
import com.xmtlxx.wms.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;


/**
 * @author RonyChan
 * @since 2022/9/02 10:01
 */
@Api(value = "API接口", tags = {"API接口"})
@Slf4j
@RestController
@RequestMapping("/openApi")
public class ApiController extends BaseController {

    @Autowired
    private IStagingService iStagingService;

    @Autowired
    private IClassifyService iClassifyService;

    @Autowired
    private ISysDeptService iSysDeptService;

    @Autowired
    private ILocatorService iLocatorService;

    @Autowired
    private ICabinetGroupService iCabinetGroupService;

    @Autowired
    private IPutDtlService iPutDtlService;

    @Autowired
    private IPutTaskService iPutTaskService;

    @Autowired
    private IPickService iPickService;

    @Autowired
    private SmartCabinetService smartCabinetService;

    @Autowired
    private ITaskService iTaskService;

    @Autowired
    private ISysOssConfigService iSysOssConfigService;

    @Autowired
    private ISysOssService iSysOssService;

    @Autowired
    private IBiService iBiService;

    @Autowired
    private ISysDictDataService iSysDictDataService;

    @Autowired
    private ISuperviseService iSuperviseService;

    @Autowired
    private IDealService iDealService;

    @Autowired
    private IInventoryService iInventoryService;

    @Autowired
    private IPropertyLogService iPropertyLogService;

    @Autowired
    private IStoreService iStoreService;

    @Autowired
    private IPropertyService iPropertyService;

    @Autowired
    private ITaskDtlService iTaskDtlService;

    @Autowired
    private IOperatorLogService iOperatorLogService;

    @Autowired
    private IOrderService iOrderService;

    @Autowired
    private ICommonService iCommonService;

    @Autowired
    private IHandoverService iHandoverService;

    @Autowired
    private IDealDtlService iDealDtlService;

    @Autowired
    private ICenterService centerService;

    @Autowired
    private TaskDtlMapper taskDtlService;

    @Autowired
    private TaskMapper taskService;

    @Autowired
    private OrderMapper orderMapper;

    @Autowired
    private ExWarehouseMapper exWarehouseMapper;

    @Autowired
    private TaskDisposalInfoMapper taskDisposalInfoMapper;

    @Autowired
    private IViewingService viewingService;

    @Autowired
    private AliyunSmsService aliyunSmsService;

    private static TengboProperties tengboProperties;

    @Autowired
    public void setTengboProperties(TengboProperties tengboProperties) {

        this.tengboProperties = tengboProperties;
    }

    @ApiOperation("接收同步数据接口")
    @PostMapping("/receiveData")
    public R<Void> receiveData(@RequestBody RequestParams params) {

        log.info("receiveData::Start");
        log.info(JsonUtils.toJsonString(params));
        log.info("receiveData::End");

        switch (params.getApi()) {
            case "proBase":
                JSONObject data = JSONObject.parseObject(JsonUtils.toJsonString(params.getData()));
                JSONArray datas = data.getJSONArray("datas");
                for (int i = 0; i < datas.size(); i++) {
                    JSONObject item = datas.getJSONObject(i);
                    log.info("proBase::ITEM::START");
                    log.info(JsonUtils.toJsonString(item));
                    log.info("proBase::ITEM::END");
                    StagingBo property = new StagingBo();
                    property.setPno(item.getString("wpbh"));
                    property.setCaseNo(item.getString("caseNo"));
                    property.setName(item.getString("proName"));
                    property.setStatus("0");
                    property.setName(item.getString("proName"));
                    property.setRegisterer(item.getString("personName"));

                    if (!StringUtils.isEmpty(item.getString("proCategory"))) {
                        //物品分类编码 item.getString("proCategory")
                        ClassifyVo first = iClassifyService.getClassifyVoByLevel(item.getString("proCategory"), 0l, null);
                        if (first != null) {
                            property.setClassifyId(first.getId());
                            //二级分类编码 item.getString("secCategory")
                            if (!StringUtils.isEmpty(item.getString("secCategory"))) {
                                ClassifyVo second = iClassifyService.getClassifyVoByLevel(item.getString("secCategory"), 1l, first.getId());
                                if (second != null) {
                                    property.setSecondClassifyId(second.getId());
                                    //三级分类编码 item.getString("thirdCategory")
                                    if (!StringUtils.isEmpty(item.getString("thirdCategory"))) {
                                        ClassifyVo third = iClassifyService.getClassifyVoByLevel(item.getString("thirdCategory"), 2l, second.getId());
                                        if (third != null) {
                                            property.setThirdClassifyId(third.getId());
                                        }
                                    }
                                }
                            }
                        }
                    }

                    property.setFeature(item.getString("feature"));
//                    property.setDelFlag(item.getString("delFlag"));
                    property.setRegisterer(item.getString("personName"));
                    if (!StringUtils.isEmpty(item.getString("officeId"))) {
                        SysDept dept = iSysDeptService.getDeptByDeptCode(item.getString("officeId"));
                        if (dept != null) {
                            property.setOfficeId(dept.getDeptId());
                        }
                    }
                    if (!StringUtils.isEmpty(item.getString("belongOfficeId"))) {
                        SysDept dept = iSysDeptService.getDeptByDeptCode(item.getString("belongOfficeId"));
                        if (dept != null) {
                            property.setTransferDept(dept.getDeptId());
                        }
                    }
                    if (!StringUtils.isEmpty(item.getString("underTaker"))) {
                        SysDept dept = iSysDeptService.getDeptByDeptCode(item.getString("underTaker"));
                        if (dept != null) {
                            property.setDeptId(dept.getDeptId());
                            property.setTransferDeptName(dept.getDeptName());
                        } else {
                            String underTaker = item.getString("underTaker");
                            if (underTaker.startsWith("8")) {
                                property.setTransferDeptName("检察院");
                            } else if (underTaker.startsWith("1")) {
                                property.setTransferDeptName("法院");
                            }
                        }
                    }
                    if (!StringUtils.isEmpty(item.getString("proNum")) && !item.getString("proNum").contains(".")) {
                        property.setNums(Long.valueOf(item.getString("proNum")));
                    }
                    if (!StringUtils.isEmpty(item.getString("createDate"))) {
                        Date createDate = new Date(Long.valueOf(item.getString("createDate")));
                        property.setCreateTime(createDate);
                        property.setRegisterTime(createDate);
                    }
                    if (!StringUtils.isEmpty(item.getString("updateDate"))) {
                        Date updateDate = new Date(Long.valueOf(item.getString("updateDate")));
                        property.setUpdateTime(updateDate);
                    }
                    property.setUnit(item.getString("unit"));
                    property.setCreateBy("admin");
                    property.setUpdateBy("admin");
                    property.setSource(0);
                    if (item.get("custodianPlace") != null && !StringUtils.isEmpty(item.getString("custodianPlace"))) {
                        property.setCustodianPlace(item.getString("custodianPlace"));
                    }
                    if (item.get("warehouseLocation") != null && !StringUtils.isEmpty(item.getString("warehouseLocation"))) {
                        property.setWarehouseLocation(item.getString("warehouseLocation"));
                    }
                    iStagingService.insertApiByBo(property);
                }
                break;
            case "inWarehouse":
                log.info("InTaskDatasVo::Data::Start");
                log.info(JsonUtils.toJsonString(params.getData()));
                log.info("InTaskDatasVo::Data::End");
                List<InTaskDatasVo> inTaskDatasVos = JsonUtils.parseArray(JsonUtils.toJsonString(params.getData()), InTaskDatasVo.class);
                for (InTaskDatasVo inTaskDatasVo : inTaskDatasVos) {
                    TaskBo bo = BeanUtil.toBean(inTaskDatasVo, TaskBo.class);
                    bo.setSource("1");
                    bo.setCheckStatus("0");
                    bo.setTakeContacts(inTaskDatasVo.getConsignee());
                    bo.setTakeTel(inTaskDatasVo.getConsigneeTel());
//                    SysDept dept = iSysDeptService.getDeptByDeptCode(inTaskDatasVo.getDeptNo());
//                    if(dept != null){
//                        bo.setTakeDept(dept.getDeptId());
//                    }
//                    List<TaskDtlVo> dtls = BeanUtil.copyToList(inTaskDatasVo.getProBase(),TaskDtlVo.class);
//                    List<TaskDtlVo> dtls = inTaskDatasVo.getProBase().stream().map(dtl ->  BeanUtil.toBean(dtl,TaskDtlVo.class)).collect(Collectors.toList());
                    List<TaskDtlVo> dtls = new ArrayList<>();
                    if (inTaskDatasVo.getProBase() != null && inTaskDatasVo.getProBase().size() > 0) {
                        for (InTaskDatasDtlVo dtl : inTaskDatasVo.getProBase()) {
                            dtls.add(BeanUtil.toBean(dtl, TaskDtlVo.class));
                        }
                    }
                    bo.setItems(dtls);
                    bo.setType("0");
                    iTaskService.insertByAPI(bo);
                }
                break;
            case "inboundOrders":
                log.info("InTaskDatasVo::Data::Start");
                log.info(JsonUtils.toJsonString(params.getData()));
                log.info("InTaskDatasVo::Data::End");
                InTaskDatasVo inTaskDatasVo = JsonUtils.parseObject(JsonUtils.toJsonString(params.getData()), InTaskDatasVo.class);
                TaskBo taskBo = BeanUtil.toBean(inTaskDatasVo, TaskBo.class);
                taskBo.setSource("1");
                taskBo.setCheckStatus("0");
                taskBo.setTakeContacts(inTaskDatasVo.getConsignee());
                taskBo.setTakeTel(inTaskDatasVo.getConsigneeTel());
//                    SysDept dept = iSysDeptService.getDeptByDeptCode(inTaskDatasVo.getDeptNo());
//                    if(dept != null){
//                        bo.setTakeDept(dept.getDeptId());
//                    }
//                    List<TaskDtlVo> dtls = BeanUtil.copyToList(inTaskDatasVo.getProBase(),TaskDtlVo.class);
//                    List<TaskDtlVo> dtls = inTaskDatasVo.getProBase().stream().map(dtl ->  BeanUtil.toBean(dtl,TaskDtlVo.class)).collect(Collectors.toList());
                List<TaskDtlVo> orderDtls = new ArrayList<>();
                if (inTaskDatasVo.getItems() != null && inTaskDatasVo.getItems().size() > 0) {
                    for (InTaskDatasDtlVo dtl : inTaskDatasVo.getItems()) {
                        orderDtls.add(BeanUtil.toBean(dtl, TaskDtlVo.class));
                    }
                }
                taskBo.setItems(orderDtls);
                taskBo.setType("0");
                iTaskService.insertTaskByAPI(taskBo);
                break;
            case "outWarehouse":
                log.info("OutTaskDatasVo::Data::Start");
                log.info(JsonUtils.toJsonString(params.getData()));
                log.info("OutTaskDatasVo::Data::End");
                List<OutTaskDatasVo> outTaskDatasVos = JsonUtils.parseArray(JsonUtils.toJsonString(params.getData()), OutTaskDatasVo.class);
                for (OutTaskDatasVo outTaskDatasVo : outTaskDatasVos) {
                    TaskBo bo = BeanUtil.toBean(outTaskDatasVo, TaskBo.class);
                    bo.setIsPushTask(true);
                    SysDept dept = iSysDeptService.getDeptByDeptCode(outTaskDatasVo.getDeptNo());
                    if (dept != null) {
                        bo.setDeptId(dept.getDeptId());
                    } else {
                        throw new ServiceException("查询不到当前单位编号！");
                    }
                    bo.setTakeContacts(outTaskDatasVo.getConsignee());
                    bo.setTel(outTaskDatasVo.getConsigneeTel());
                    bo.setTaskNo(outTaskDatasVo.getCallNo());
                    List<TaskDtlVo> dtls = new ArrayList<>();
                    if (outTaskDatasVo.getItems() != null && outTaskDatasVo.getItems().size() > 0) {
                        for (OutTaskDatasDtlVo dtl : outTaskDatasVo.getItems()) {
                            TaskDtlVo taskDtlVo = BeanUtil.toBean(dtl, TaskDtlVo.class);
                            taskDtlVo.setPno(dtl.getProNo());
                            SysDept dtlDept = iSysDeptService.getDeptByDeptCode(dtl.getDeptNo());
                            if (dtlDept != null) {
                                taskDtlVo.setDeptId(dtlDept.getDeptId());
                            }

                            InventoryVo inventoryVo = iInventoryService.selectByPno(dtl.getPno());
                            if (inventoryVo != null) {
                                taskDtlVo.setClassifyId(inventoryVo.getClassifyId());
                                taskDtlVo.setCharacter(inventoryVo.getCharacter());
                            }

                            dtls.add(taskDtlVo);
                        }
                    }
//                    outTaskDatasVo.getProBase().stream().map(dtl ->  BeanUtil.toBean(dtl,TaskDtlVo.class)).collect(Collectors.toList());
                    bo.setItems(dtls);
                    TaskVo insertVo = iTaskService.insertByOutWarehouseAPI(bo);
                    if (insertVo != null && StringUtils.isNotBlank(insertVo.getId()) && insertVo.getDelivery().equals("1")) {
                        SendTaskVo sendTaskVo = new SendTaskVo();
                        sendTaskVo.setStoreId(insertVo.getStoreId());
                        sendTaskVo.setCarrierDeptId(0l);
                        String[] ids = new String[]{insertVo.getId()};
                        sendTaskVo.setIds(ids);
                        centerService.sendsTask(sendTaskVo);
                    }
                }
                break;
            case "returnInfo":
                log.info("ReturnTaskDataVo::Data::Start");
                log.info(JsonUtils.toJsonString(params.getData()));
                log.info("ReturnTaskDataVo::Data::End");
                List<InTaskDatasVo> returnInTaskDatasVos = JsonUtils.parseArray(JsonUtils.toJsonString(params.getData()), InTaskDatasVo.class);
                for (InTaskDatasVo returnTaskDataVo : returnInTaskDatasVos) {
                    TaskBo bo = BeanUtil.toBean(returnTaskDataVo, TaskBo.class);
                    bo.setIsPushTask(true);
                    TaskBo query = new TaskBo();
                    query.setTaskNo(returnTaskDataVo.getProCallNo());
                    TaskVo dTask = iTaskService.selectTaskVoByTaskNo(query);

                    if (dTask != null) {
                        List<TaskDtlVo> dtls = new ArrayList<>();
                        SysDept dept = iSysDeptService.getDeptByDeptCode(returnTaskDataVo.getDeptNo());
                        if (dept != null) {
                            bo.setDeptId(dept.getDeptId());
                        } else {
                            throw new ServiceException("查询不到当前单位编号！");
                        }
                        if (returnTaskDataVo.getItems() != null && returnTaskDataVo.getItems().size() > 0) {
                            for (InTaskDatasDtlVo dtl : returnTaskDataVo.getItems()) {
                                TaskDtlVo taskDtlVo = BeanUtil.toBean(dtl, TaskDtlVo.class);
                                taskDtlVo.setPno(dtl.getProNo());
                                SysDept dtlDept = iSysDeptService.getDeptByDeptCode(dtl.getDeptNo());
                                if (dtlDept != null) {
                                    taskDtlVo.setDeptId(dtlDept.getDeptId());
                                }

                                InventoryVo inventoryVo = iInventoryService.selectByPno(taskDtlVo.getPno());
                                if (inventoryVo != null) {
                                    taskDtlVo.setClassifyId(inventoryVo.getClassifyId());
                                    taskDtlVo.setCharacter(inventoryVo.getCharacter());
                                }

                                dtls.add(taskDtlVo);
                            }
                        }
                        bo.setName(returnTaskDataVo.getReturnPerson());
                        bo.setAddress(returnTaskDataVo.getAddress());
                        bo.setNums(returnTaskDataVo.getReturnNumber());
                        bo.setReturnId(dTask.getId());
                        bo.setDispatchRemark(returnTaskDataVo.getDamagedCause());//损坏原因

                        //调用归还单
                        bo.setTaskNo(dTask.getTaskNo() + "-归");

                        /**
                         * 损耗说明附件
                         */
                        List<String> filePaths = returnTaskDataVo.getFilePath();
                        List<SysOss> ossList = new ArrayList<>();
                        if (filePaths != null && filePaths.size() > 0) {
                            SysOssConfigVo ossConfig = iSysOssConfigService.getDefaultConfig();
                            for (String filePath : filePaths) {
                                SysOss oss = new SysOss();
                                oss.setFileName(filePath);
                                oss.setService("minio");
                                oss.setCreateBy("接口推送");
                                oss.setUpdateBy("接口推送");
                                oss.setOriginalName(oss.getFileName().substring(oss.getFileName().lastIndexOf("/") + 1));
                                oss.setFileSuffix(oss.getFileName().substring(oss.getFileName().lastIndexOf(".") + 1));
                                oss.setUrl((StringUtils.isNotEmpty(ossConfig.getPrefix()) ? ossConfig.getPrefix() : ossConfig.getEndpoint()) + "/minio" + oss.getFileName());
                                iSysOssService.addOss(oss);
                                ossList.add(oss);
                            }
                        }
                        bo.setOss(ossList);
                        bo.setItems(dtls);
                        TaskVo insertVo = iTaskService.insertByOutWarehouseAPI(bo);
                        if (insertVo != null && StringUtils.isNotBlank(insertVo.getId()) && insertVo.getDelivery().equals("1")) {
                            SendTaskVo sendTaskVo = new SendTaskVo();
                            sendTaskVo.setStoreId(insertVo.getStoreId());
                            sendTaskVo.setCarrierDeptId(0l);
                            String[] ids = new String[]{insertVo.getId()};
                            sendTaskVo.setIds(ids);
                            centerService.sendsTask(sendTaskVo);
                        }

                    }
                }
                break;
            case "picture":
                JSONArray picDatas = JSONArray.parseArray(JsonUtils.toJsonString(params.getData()));
                SysOssConfigVo ossConfig = iSysOssConfigService.getDefaultConfig();
                for (int i = 0; i < picDatas.size(); i++) {
                    JSONObject item = picDatas.getJSONObject(i);
                    SysOss oss = new SysOss();
                    oss.setBuss("property");
                    oss.setObjid(item.getString("proNo"));
                    oss.setFileName(item.getString("antPath"));
                    oss.setService("minio");
                    oss.setCreateBy("接口推送");
                    oss.setUpdateBy("接口推送");
                    oss.setOriginalName(oss.getFileName().substring(oss.getFileName().lastIndexOf("/") + 1));
                    oss.setFileSuffix(oss.getFileName().substring(oss.getFileName().lastIndexOf(".") + 1));
                    oss.setUrl((StringUtils.isNotEmpty(ossConfig.getPrefix()) ? ossConfig.getPrefix() : ossConfig.getEndpoint()) + "/minio" + oss.getFileName());
                    iSysOssService.addOss(oss);
                }
                break;
            case "disposalOpinions":
                JSONArray dealArrays = JSONArray.parseArray(JsonUtils.toJsonString(params.getData()));

                JSONObject dealObj = dealArrays.getJSONObject(0);
                JSONArray dealDatas = JSONArray.parseArray(dealObj.get("datas").toString());
                String officeId = dealObj.getString("officeId");//处置意见单位
                String disposalTime = dealObj.getString("disposalTime");//处置时间
                String officeName = dealObj.getString("officeName");//裁决单位
                String wsPdf = dealObj.getString("wsPdf");//文书
                for (int i = 0; i < dealDatas.size(); i++) {
                    JSONObject dealDtlObj = dealDatas.getJSONObject(i);

                    DealBo bo = new DealBo();
                    bo.setDealNo(dealDtlObj.getString("proNo"));
                    DealVo dealVo = iDealService.getDealByVo(bo);
                    if (dealVo == null) {
                        DealDtlVo dtlVo = new DealDtlVo();
                        dtlVo.setPno(dealDtlObj.getString("proNo"));
                        bo.setDealType(dealDtlObj.getString("itemHandleWay"));
                        dtlVo.setDealType(dealDtlObj.getString("itemHandleWay"));
                        dtlVo.setName(dealDtlObj.getString("proName"));
                        dtlVo.setHandleUnitName(dealDtlObj.getString("handleUnitName"));
                        dtlVo.setHelpUnitName(dealDtlObj.getString("helpUnitName"));
                        //查询当前在库情况
                        InventoryVo inventoryVo = iInventoryService.queryByPno(dealDtlObj.getString("proNo"), null, "0");
                        if (inventoryVo != null) {
                            bo.setStoreId(inventoryVo.getStoreId());
                            dtlVo.setStoreId(inventoryVo.getStoreId());
                            bo.setNums(inventoryVo.getNums());
                            dtlVo.setNums(inventoryVo.getNums());
                            dtlVo.setStoreId(inventoryVo.getStoreId());
                            if (StringUtils.isNotEmpty(inventoryVo.getAreaId())) {
                                dtlVo.setAreaId(inventoryVo.getAreaId());
                            }
                            if (StringUtils.isNotEmpty(inventoryVo.getLocatorId())) {
                                dtlVo.setLocatorId(inventoryVo.getLocatorId());
                            }
                            bo.setIsCheck("0");
                        } else {
                            bo.setMemo("当前物品不在库");
                            bo.setNums(0l);
                            dtlVo.setNums(0l);
                        }
                        bo.setOfficeName(officeName);
                        bo.setOfficeId(iSysDeptService.getDeptByDeptCode(officeId).getDeptId());
                        bo.setDisposalTime(DateUtils.dateTime("yyyy-MM-dd HH:mm:ss", disposalTime));
                        bo.setWsPdf(wsPdf);
                        bo.setBelieve(dealDtlObj.getString("itemSource"));
                        List<DealDtlVo> items = new ArrayList<>();
                        items.add(dtlVo);
                        bo.setItems(items);
                        iDealService.insertByDealBo(bo);
                    } else {
                        DealBo oldBo = new DealBo();
                        BeanUtil.copyProperties(dealVo, oldBo);
                        if (!oldBo.getIsCheck().equals("1")) {//审核状态 0-待审核 1-审核通过 -1-审核不通过
                            oldBo.setIsCheck("0");
                        }

                        //查询当前在库情况
                        InventoryVo inventoryVo = iInventoryService.queryByPno(dealDtlObj.getString("proNo"), null, "0");
                        DealDtlBo dealDtlBo = new DealDtlBo();
                        dealDtlBo.setDealId(oldBo.getId());
                        DealDtlVo dtlVo = iDealDtlService.queryByBo(dealDtlBo);
                        if (inventoryVo != null) {
                            oldBo.setStoreId(inventoryVo.getStoreId());
                            oldBo.setNums(inventoryVo.getNums());
                            oldBo.setMemo(null);
                            dtlVo.setStoreId(inventoryVo.getStoreId());
                            dtlVo.setNums(inventoryVo.getNums());
                            dtlVo.setStoreId(inventoryVo.getStoreId());
                            if (StringUtils.isNotEmpty(inventoryVo.getAreaId())) {
                                dtlVo.setAreaId(inventoryVo.getAreaId());
                            }
                            if (StringUtils.isNotEmpty(inventoryVo.getLocatorId())) {
                                dtlVo.setLocatorId(inventoryVo.getLocatorId());
                            }
                        } else {
                            oldBo.setMemo("当前物品不在库");
                            oldBo.setNums(0l);
                            dtlVo.setNums(0l);
                        }
                        List<DealDtlVo> items = new ArrayList<>();
                        items.add(dtlVo);
                        oldBo.setItems(items);
                        iDealService.updateByDealBo(oldBo);
                    }
                }

                break;
            case "supervise":
                List<SuperviseDatasVo> inSuperviseDatasDatasVo = JsonUtils.parseArray(JsonUtils.toJsonString(params.getData()), SuperviseDatasVo.class);
                for (SuperviseDatasVo superviseDatasVo : inSuperviseDatasDatasVo) {
                    SuperviseBo bo = BeanUtil.toBean(superviseDatasVo, SuperviseBo.class);
                    iSuperviseService.insertByBo(bo);
                }
                break;
            case "proWatch":
                List<RemoteDataVo> remoteDataVos = JsonUtils.parseArray(JsonUtils.toJsonString(params.getData()), RemoteDataVo.class);
                if (remoteDataVos != null && remoteDataVos.size() > 0) {
                    for (RemoteDataVo vo : remoteDataVos) {
                        ViewingBo bo = BeanUtil.toBean(vo, ViewingBo.class);
                        bo.setId(null);
                        bo.setRelatedId(vo.getId());
                        SysDept dept = iSysDeptService.getDeptByDeptCode(vo.getDeptId());
                        if (dept != null) {
                            bo.setDeptId(iSysDeptService.getDeptByDeptCode(vo.getDeptId()).getDeptId());
                        } else {
                            throw new ServiceException("查无此部门");
                        }
                        List<ViewingDtlVo> items = vo.getItems().stream().map(item -> {
                            ViewingDtlVo dtlVo = BeanUtil.toBean(item, ViewingDtlVo.class);
                            dtlVo.setPno(item.getProNo());
                            return dtlVo;
                        }).collect(Collectors.toList());
                        bo.setItems(items);

                        viewingService.insertByReceive(bo);
                    }
                }

                break;
        }
        return R.ok();
    }


    @ApiOperation("入库同步数据接口对象信息")
    @PostMapping("/inModels")
    public R<Void> inModels(@RequestBody InModelsVo modelsVo) {

        return R.ok();
    }

    @ApiOperation("出库同步数据接口对象信息")
    @PostMapping("/outModels")
    public R<Void> outModels(@RequestBody OutModelsVo modelsVo) {

        return R.ok();
    }

    @ApiOperation("盘点计划结果同步数据接口对象信息")
    @PostMapping("/planModels")
    public R<Void> planModels(@RequestBody PlanModelsVo modelsVo) {

        return R.ok();
    }

    @ApiOperation("财物同步数据接口对象信息")
    @PostMapping("/propertyModels")
    public R<Void> propertyModels(@RequestBody PropertyModelsVo modelsVo) {

        return R.ok();
    }

    @ApiOperation("看样同步数据接口对象信息")
    @PostMapping("/viewModels")
    public R<List<ViewingVo>> viewModels(@RequestBody ViewModelsVo modelsVo) {

        return R.ok(viewingService.getViewingVos());
    }

    @ApiOperation("财物登记同步数据接口对象信息")
    @PostMapping("/stagingModels")
    public R<Void> stagingModels(@RequestBody StagingModelsVo modelsVo) {

        return R.ok();
    }

    @ApiOperation("财物日志同步数据接口对象信息")
    @PostMapping("/propertyLogModels")
    public R<Void> propertyLogModels(@RequestBody PropertyLogModelsVo modelsVo) {

        return R.ok();
    }

    @ApiOperation("仓库信息同步数据接口对象信息")
    @PostMapping("/storeModels")
    public R<Void> storeModels(@RequestBody StoreModelsVo modelsVo) {

        return R.ok();
    }

    @ApiOperation("订单信息同步数据接口对象信息")
    @PostMapping("/orderModels")
    public R<Void> orderModels(@RequestBody OrderModelsVo modelsVo) {

        return R.ok();
    }

    @ApiOperation("运单信息同步数据接口对象信息")
    @PostMapping("/waybillModels")
    public R<Void> waybillModels(@RequestBody WayBillModelsVo modelsVo) {

        return R.ok();
    }


    @ApiOperation("上架任务同步数据接口对象信息")
    @PostMapping("/putTask")
    public R<Void> putTask(@RequestBody PutTaskDataModelsVo modelsVo) {

        return R.ok();
    }

    @ApiOperation("挑拣任务同步数据接口对象信息")
    @PostMapping("/pickTask")
    public R<Void> pickTask(@RequestBody PickTaskDataModelsVo modelsVo) {

        return R.ok();
    }

    @ApiOperation("智能柜同步数据接口对象信息")
    @GetMapping("cabinetModels/{sncode}/{groupId}")
    public R<Void> cabinetModels(@ApiParam("SN码") @NotEmpty(message = "SN码不能为空") @PathVariable String sncode, @PathVariable String groupId) {

        log.info("cabinetModels::Start");
        log.info(sncode);
        log.info("cabinetModels::End");

//        String api = "http://10.210.151.7:82/stage-api/business/rela/qryAllAisleByEquCode/"+sncode;
//        String api = "http://fjzy.zcloudtechs.cn:2426/stage-api/business/rela/qryAllAisleByEquCode/"+sncode;
        String api = tengboProperties.getSmarturl() + sncode;
        try {
            String params = HttpInvokerUtils.GET(api);
            log.info(JsonUtils.toJsonString(params));
            JSONArray cabinetAisleList = JSONObject.parseObject(params).getJSONObject("data").getJSONArray("cabinetAisleList");
            List<AisleVo> aisleList = new ArrayList<>();
            aisleList = cabinetAisleList.stream().map(item -> {
                AisleVo vo = new AisleVo();
                BeanUtil.copyProperties(item, vo);
                return vo;
            }).collect(Collectors.toList());

            CabinetGroup cabinetGroup = iCabinetGroupService.getById(groupId);

            List<LocatorBo> boList = aisleList.stream().map(item -> {
                LocatorBo bo = new LocatorBo();
                BeanUtil.copyProperties(item, bo);
                bo.setName(item.getAisleCode());
                bo.setStoreId(cabinetGroup.getStoreId());
                bo.setAreaId(cabinetGroup.getAreaId());
                bo.setCabinetGroupId(groupId);
                bo.setRegion(cabinetGroup.getRegion());//设置地域
                if (StringUtils.isNotEmpty(item.getAisleCode()) && StringUtils.isAllNumbric(item.getAisleCode())) {
                    bo.setSeq(Integer.valueOf(item.getAisleCode()));
                }

                return bo;
            }).collect(Collectors.toList());
            Long totals = iLocatorService.insertByWithBo(boList, groupId);
            cabinetGroup.setLnums(totals);
            iCabinetGroupService.updateByEntity(cabinetGroup);
            return toAjax(totals > 0);

        } catch (Exception e) {
            e.printStackTrace();
        }


        return R.ok();
    }

    @ApiOperation("待入柜物品同步数据接口")
    @GetMapping("/smartCabinet/getProV2")
    public R<List<SmartCabinetPutProtVo>> getProV2(@ApiParam("唯一编码") @NotEmpty(message = "唯一编码不能为空") String smartCabinetId) {

        log.info("smartCabinet/getProV2::Start");
        log.info(smartCabinetId);
        log.info("smartCabinet/getProV2::End");
        return R.ok(iPutDtlService.queryDtlBySmartCabinetId(smartCabinetId));
    }

    @ApiOperation("待出柜物品同步数据接口")
    @GetMapping("/smartCabinet/getOutPro")
    public R<List<SmartCabinetPickProVo>> getOutPro(@ApiParam("唯一编码") @NotEmpty(message = "唯一编码不能为空") String smartCabinetId) {

        return R.ok(iPickService.getSmartCabinetPickPro(smartCabinetId));
    }

    @ApiOperation("验证待出柜物品验证码")
    @GetMapping("/smartCabinet/verifyOutProCode")
    public R<Void> verifyOutProCode(@ApiParam("物品id") @NotBlank(message = "物品id不能为空") String proId,
                                    @ApiParam("验证码") @NotBlank(message = "验证码不能为空") String code) {

        return smartCabinetService.verifySmartCabinetCode(proId, code, 0);
    }

    @ApiOperation("验证待一键开柜验证码")
    @GetMapping("/smartCabinet/verifyOpenAllCode")
    public R<Void> verifyOpenAllCode(@ApiParam("唯一编码不能为空") @NotBlank(message = "唯一编码不能为空不能为空") String smartCabinetId,
                                     @ApiParam("验证码") @NotBlank(message = "验证码不能为空") String code) {

        return smartCabinetService.verifySmartCabinetCode(smartCabinetId, code, 1);
    }


    @ApiOperation("已入柜物品同步数据接口")
    @PostMapping("/smartCabinet/proBatchInSmartCabinet")
    @Log(title = "智能柜物品入柜", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class)
    public R<Void> proBatchInSmartCabinet(@RequestBody SmartCabinetInVo data) {

        log.info("smartCabinet/proBatchInSmartCabine::Start");
        log.info(JsonUtils.toJsonString(data));
        log.info("smartCabinet/proBatchInSmartCabine::End");
        iPutTaskService.syncUpdateBySmartCabinet(data);
        return R.ok();
    }

    @ApiOperation("已出柜物品同步数据接口")
    @PostMapping("/smartCabinet/proBatchOutSmartCabinet")
    @Log(title = "智能柜物品出柜", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class)
    public R<Void> proBatchOutSmartCabinet(@RequestBody SmartCabinetOutVo data) {

        log.info("smartCabinet/proBatchOutSmartCabinet::Start");
        log.info(JsonUtils.toJsonString(data));
        log.info("smartCabinet/proBatchOutSmartCabinet::End");
        iPickService.syncUpdateBatchOutSmartCabinet(data);
        return R.ok();
    }

    @ApiOperation("Bi数据接口")
    @GetMapping("/Bi/datas/{source}")
    public R<List<JSONObject>> proBatchOutSmartCabinet(@ApiParam("数据类型")
                                                       @NotNull(message = "数据类型不能为空")
                                                       @PathVariable("source") Integer source) {

        List<JSONObject> result = new ArrayList<>();
        List<Map<String, Object>> items = new ArrayList<>();
        List<Map<String, Object>> counts = new ArrayList<>();
        SysDictData dictData = new SysDictData();
        dictData.setDictType("wms_put_task_area");
        List<SysDictData> dictDataList = iSysDictDataService.selectDictDataList(dictData);
        switch (source) {
            case 1:
                counts = iBiService.selectCountStagings();
                for (SysDictData data : dictDataList) {
                    if (data.getDictValue().equals("QB") || data.getDictValue().equals("SZ")) {
                        continue;
                    }
                    String region = data.getDictLabel();
                    if (data.getDictValue().equals("QB")) {
                        region = null;
                    } else if (data.getDictValue().equals("SZ")) {
                        region = "市直";
                    } else if (data.getDictValue().equals("YA")) {
                        region = data.getDictLabel() + "市";
                    } else if (data.getDictValue().equals("SY") || data.getDictValue().equals("SX")) {
                        region = data.getDictLabel() + "区";
                    } else {
                        region = data.getDictLabel() + "县";
                    }
                    Map<String, Object> val1 = new HashMap<>();
                    Long alls = 0l;
                    Long receives = 0l;
                    if (counts != null && counts.size() > 0) {
                        for (Map<String, Object> c : counts) {
                            if (Objects.equals(c.get("REGION"), data.getDictValue())) {
                                alls = c.get("ALLS") != null && StringUtils.isNotEmpty(c.get("ALLS").toString()) ? Long.valueOf(c.get("ALLS").toString()) : 0l;
                                receives = c.get("RECEIVES") != null && StringUtils.isNotEmpty(c.get("RECEIVES").toString()) ? Long.valueOf(c.get("RECEIVES").toString()) : 0l;
                            }
                        }
                    }
                    val1.put("y1", region);
                    val1.put("x1", receives);
                    val1.put("s1", "登记数");
                    items.add(val1);
                    Map<String, Object> val2 = new HashMap<>();
                    val2.put("y1", region);
                    val2.put("x1", alls);
                    val2.put("s1", "采集数");
                    items.add(val2);
                }

                result = items.stream().map(i ->
                        JSONObject.parseObject(JsonUtils.toJsonString(i))
                ).collect(Collectors.toList());
                break;
            case 2:
                counts = iBiService.selectCountStock();

                for (SysDictData data : dictDataList) {
                    if (data.getDictValue().equals("QB")) {
                        continue;
                    }
                    Map<String, Object> val1 = new HashMap<>();
                    Long buses = 0l;
                    Long ops = 0l;
                    if (counts != null && counts.size() > 0) {
                        for (Map<String, Object> c : counts) {
                            if (Objects.equals(c.get("REGION"), data.getDictValue())) {
                                buses = c.get("BUSES") != null && StringUtils.isNotEmpty(c.get("BUSES").toString()) ? Long.valueOf(c.get("BUSES").toString()) : 0l;
                                ops = c.get("OPS") != null && StringUtils.isNotEmpty(c.get("OPS").toString()) ? Long.valueOf(c.get("OPS").toString()) : 0l;
                            }
                        }
                    }
                    val1.put("y2", data.getDictLabel());
                    val1.put("x2", buses);
                    val1.put("s2", "车辆数");
                    items.add(val1);
                    Map<String, Object> val2 = new HashMap<>();
                    val2.put("y2", data.getDictLabel());
                    val2.put("x2", ops);
                    val2.put("s2", "物品数");
                    items.add(val2);
                }
                result = items.stream().map(i -> JSONObject.parseObject(JsonUtils.toJsonString(i))).collect(Collectors.toList());
                break;
            case 3:
                Map<String, Object> c = iBiService.selectCountOrder();
                Long tols = 0l;
                Long unsends = 0l;
                Long isTrades = 0l;
                Long signs = 0l;
                Long inorders = 0l;
                Long outorders = 0l;
                if (c != null) {
                    //总订单数
                    tols = c.get("TOLS") != null && StringUtils.isNotEmpty(c.get("TOLS").toString()) ? Long.valueOf(c.get("TOLS").toString()) : 0l;
                    //待下发
                    unsends = c.get("UNSENDS") != null && StringUtils.isNotEmpty(c.get("UNSENDS").toString()) ? Long.valueOf(c.get("UNSENDS").toString()) : 0l;
                    //运输中
                    isTrades = c.get("ISTRADES") != null && StringUtils.isNotEmpty(c.get("ISTRADES").toString()) ? Long.valueOf(c.get("ISTRADES").toString()) : 0l;
                    //已签收
                    signs = c.get("SIGNS") != null && StringUtils.isNotEmpty(c.get("SIGNS").toString()) ? Long.valueOf(c.get("SIGNS").toString()) : 0l;
                    //入库单数
                    inorders = c.get("INORDERS") != null && StringUtils.isNotEmpty(c.get("INORDERS").toString()) ? Long.valueOf(c.get("INORDERS").toString()) : 0l;
                    //出库单数
                    outorders = c.get("OUTORDERS") != null && StringUtils.isNotEmpty(c.get("OUTORDERS").toString()) ? Long.valueOf(c.get("OUTORDERS").toString()) : 0l;
                }
                Map<String, Object> data = new HashMap<>();
                data.put("value3_1", tols);
                data.put("text3_1", "总订单数：" + tols);
                data.put("value3_2", unsends);
                data.put("text3_2", "待下发订单数：" + unsends);
                data.put("value3_3", isTrades);
                data.put("text3_3", "运输中订单数：" + isTrades);
                data.put("value3_4", signs);
                data.put("text3_4", "已签收订单数：" + signs);
                data.put("value3_5", inorders);
                data.put("text3_5", "入库订单数：" + inorders);
                data.put("value3_6", outorders);
                data.put("text3_6", "出库订单数：" + outorders);
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(data)));
                break;
            case 4:
                TaskBo taskBo = new TaskBo();
                taskBo.setDelFlag("0");
                PageQuery pageQuery = new PageQuery();
                pageQuery.setPageNum(1);
                pageQuery.setPageSize(50);
                TableDataInfo<TaskVo> page = iTaskService.queryPageListWithOutLogin(taskBo, pageQuery);
                if (page != null && page.getRows() != null && page.getRows().size() > 0) {
                    result = page.getRows().stream().map(i -> {
                        Map<String, Object> m = new HashMap<>();
                        String label = "";
                        if (StringUtils.isNotEmpty(i.getRegion())) {
                            for (SysDictData d : dictDataList) {
                                if (d.getDictValue().equals(i.getRegion())) {
                                    label = d.getDictLabel();
                                }
                            }
                            ;
                        }
                        m.put("pcs", label);
                        m.put("yzjqs", i.getDeptName());
                        m.put("xs", i.getPropertyTypeName());
                        m.put("za", i.getNums());
                        m.put("jb", i.getName());
                        m.put("jf", i.getUpdateTime());
                        return JSONObject.parseObject(JsonUtils.toJsonString(m));
                    }).collect(Collectors.toList());
                }
                break;
            case 5:
                Map<String, Object> cu = iBiService.selectCountInOuts();
                Map<String, Object> outDatas5 = iBiService.selectBiData5OfOutmus();
                Map<String, Object> m = new HashMap<>();
                Long innums = 0l;
                Long outnums = 0l;
                Long inwarns = 0l;
                Long outwarns = 0l;
//                if(cu != null ){
//                    innums = cu.get("INNUMS") != null && StringUtils.isNotEmpty(cu.get("INNUMS").toString()) ? Long.valueOf(cu.get("INNUMS").toString()) : 0l;
//                    if(cu.get("RNUMS") != null && StringUtils.isNotEmpty(cu.get("RNUMS").toString())){
//                        innums += Long.valueOf(cu.get("RNUMS").toString());
//                    }
//                    outnums = cu.get("OUTNUMS") != null && StringUtils.isNotEmpty(cu.get("OUTNUMS").toString()) ? Long.valueOf(cu.get("OUTNUMS").toString()) : 0l;
//                    if(cu.get("DEALS") != null && StringUtils.isNotEmpty(cu.get("DEALS").toString())){
//                        outnums += Long.valueOf(cu.get("DEALS").toString());
//                    }
//                    if(cu.get("TNUMS") != null && StringUtils.isNotEmpty(cu.get("TNUMS").toString())){
//                        outnums += Long.valueOf(cu.get("TNUMS").toString());
//                    }
//                }
                if (outDatas5 != null && outDatas5.get("TOLS") != null && StringUtils.isNotEmpty(outDatas5.get("TOLS").toString())) {
                    outnums = Long.valueOf(outDatas5.get("TOLS").toString());
                }
                InventoryBo bo = new InventoryBo();
                bo.setType("0");
                CurrentBiVo properties = iInventoryService.countDatasCurrentTotals(bo);
                bo.setType("1");
                CurrentBiVo bus = iInventoryService.countDatasCurrentTotals(bo);
                if (properties != null) {
                    if (properties.getReceives() != null) {
                        innums += properties.getReceives();
                    }
                    if (properties.getReceivesOrder() != null) {
                        innums += properties.getReceivesOrder();
                    }
                }
                if (bus != null) {
                    if (bus.getReceives() != null) {
                        innums += bus.getReceives();
                    }
                    if (bus.getReceivesOrder() != null) {
                        innums += bus.getReceivesOrder();
                    }
                }
                m.put("value5_1", innums);
                m.put("value5_2", outnums);
                m.put("value5_3", inwarns);
                m.put("value5_4", outwarns);
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(m)));
                break;
            case 6:

                Map<String, Object> dxu = new HashMap<>();
                dxu.put("x6", "大型物品区");
                dxu.put("y7", 0);
                dxu.put("s7", "已使用");

                Map<String, Object> dxw = new HashMap<>();
                dxw.put("x6", "大型物品区");
                dxw.put("y7", 0);
                dxw.put("s7", "未使用");

                Map<String, Object> sle = iBiService.selectCountLocator("DX");
                if (sle != null && sle.get("USES") != null && StringUtils.isNotEmpty(sle.get("USES").toString())) {
                    dxu.put("y7", Long.valueOf(sle.get("USES").toString()));
                }
                if (sle != null && sle.get("UNUSES") != null && StringUtils.isNotEmpty(sle.get("UNUSES").toString())) {
                    dxw.put("y7", Long.valueOf(sle.get("UNUSES").toString()));
                }
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(dxu)));
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(dxw)));

                Map<String, Object> zxu = new HashMap<>();
                zxu.put("x6", "中型物品区");
                zxu.put("y7", 0);
                zxu.put("s7", "已使用");

                Map<String, Object> zxw = new HashMap<>();
                zxw.put("x6", "中型物品区");
                zxw.put("y7", 0);
                zxw.put("s7", "未使用");

                sle = iBiService.selectCountLocator("ZX");
                if (sle != null && sle.get("USES") != null && StringUtils.isNotEmpty(sle.get("USES").toString())) {
                    zxu.put("y7", Long.valueOf(sle.get("USES").toString()));
                }
                if (sle != null && sle.get("UNUSES") != null && StringUtils.isNotEmpty(sle.get("UNUSES").toString())) {
                    zxw.put("y7", Long.valueOf(sle.get("UNUSES").toString()));
                }
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(zxu)));
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(zxw)));

                Map<String, Object> dzu = new HashMap<>();
                dzu.put("x6", "电子设备区");
                dzu.put("y7", 0);
                dzu.put("s7", "已使用");

                Map<String, Object> dzw = new HashMap<>();
                dzw.put("x6", "电子设备区");
                dzw.put("y7", 0);
                dzw.put("s7", "未使用");
                sle = iBiService.selectCountLocator("DZ");
                if (sle != null && sle.get("USES") != null && StringUtils.isNotEmpty(sle.get("USES").toString())) {
                    dzu.put("y7", Long.valueOf(sle.get("USES").toString()));
                }
                if (sle != null && sle.get("UNUSES") != null && StringUtils.isNotEmpty(sle.get("UNUSES").toString())) {
                    dzw.put("y7", Long.valueOf(sle.get("UNUSES").toString()));
                }
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(dzu)));
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(dzw)));

                Map<String, Object> gzu = new HashMap<>();
                gzu.put("x6", "特殊物品区");
                gzu.put("y7", 0);
                gzu.put("s7", "已使用");

                Map<String, Object> gzw = new HashMap<>();
                gzw.put("x6", "特殊物品区");
                gzw.put("y7", 0);
                gzw.put("s7", "未使用");

                sle = iBiService.selectCountLocator("GZ");
                if (sle != null && sle.get("USES") != null && StringUtils.isNotEmpty(sle.get("USES").toString())) {
                    gzu.put("y7", Long.valueOf(sle.get("USES").toString()));
                }
                if (sle != null && sle.get("UNUSES") != null && StringUtils.isNotEmpty(sle.get("UNUSES").toString())) {
                    gzw.put("y7", Long.valueOf(sle.get("UNUSES").toString()));
                }
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(gzu)));
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(gzw)));

                Map<String, Object> ptu = new HashMap<>();
                ptu.put("x6", "普通物品区");
                ptu.put("y7", 0);
                ptu.put("s7", "已使用");

                Map<String, Object> ptw = new HashMap<>();
                ptw.put("x6", "普通物品区");
                ptw.put("y7", 0);
                ptw.put("s7", "未使用");

                sle = iBiService.selectCountLocator("PT");
                if (sle != null && sle.get("USES") != null && StringUtils.isNotEmpty(sle.get("USES").toString())) {
                    ptu.put("y7", Long.valueOf(sle.get("USES").toString()));
                }
                if (sle != null && sle.get("UNUSES") != null && StringUtils.isNotEmpty(sle.get("UNUSES").toString())) {
                    ptw.put("y7", Long.valueOf(sle.get("UNUSES").toString()));
                }
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(ptu)));
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(ptw)));

                Map<String, Object> clu = new HashMap<>();
                clu.put("x6", "车辆保管区");
                clu.put("y7", 0);
                clu.put("s7", "已使用");

                Map<String, Object> clw = new HashMap<>();
                clw.put("x6", "车辆保管区");
                clw.put("y7", 0);
                clw.put("s7", "未使用");

                sle = iBiService.selectCountLocator("CL");
                if (sle != null && sle.get("USES") != null && StringUtils.isNotEmpty(sle.get("USES").toString())) {
                    clu.put("y7", Long.valueOf(sle.get("USES").toString()));
                }
                if (sle != null && sle.get("UNUSES") != null && StringUtils.isNotEmpty(sle.get("UNUSES").toString())) {
                    clw.put("y7", Long.valueOf(sle.get("UNUSES").toString()));
                }
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(clu)));
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(clw)));

                break;
            case 7:
                items = iBiService.selectCountLocatorTypes();
                for (Map<String, Object> item : items) {

                    BigDecimal znAlls = BigDecimal.ONE;
                    BigDecimal znUses = BigDecimal.ZERO;
                    BigDecimal znUnUses = BigDecimal.ZERO;
                    BigDecimal ptAlls = BigDecimal.ONE;
                    BigDecimal ptUses = BigDecimal.ZERO;
                    BigDecimal ptUnUses = BigDecimal.ZERO;
                    BigDecimal carAlls = BigDecimal.ONE;
                    BigDecimal carUses = BigDecimal.ZERO;
                    BigDecimal carUnUses = BigDecimal.ZERO;

                    if (item.get("ZNALLS") != null && StringUtils.isNotEmpty(item.get("ZNALLS").toString())) {
                        znAlls = BigDecimal.valueOf(Double.valueOf(item.get("ZNALLS").toString()));
                    }
                    if (item.get("ZNUSES") != null && StringUtils.isNotEmpty(item.get("ZNUSES").toString())) {
                        znUses = BigDecimal.valueOf(Double.valueOf(item.get("ZNUSES").toString()));
                    }
                    if (item.get("PTALLS") != null && StringUtils.isNotEmpty(item.get("PTALLS").toString())) {
                        ptAlls = BigDecimal.valueOf(Double.valueOf(item.get("PTALLS").toString()));
                    }
                    if (item.get("PTUSER") != null && StringUtils.isNotEmpty(item.get("PTUSER").toString())) {
                        ptUses = BigDecimal.valueOf(Double.valueOf(item.get("PTUSER").toString()));
                    }
                    if (item.get("CARALLS") != null && StringUtils.isNotEmpty(item.get("CARALLS").toString())) {
                        carAlls = BigDecimal.valueOf(Double.valueOf(item.get("CARALLS").toString()));
                    }
                    if (item.get("CARUSES") != null && StringUtils.isNotEmpty(item.get("CARUSES").toString())) {
                        carUses = BigDecimal.valueOf(Double.valueOf(item.get("CARUSES").toString()));
                    }

                    znAlls = znAlls.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : znAlls;
                    ptAlls = ptAlls.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : ptAlls;
                    carAlls = carAlls.compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE : carAlls;

                    Map<String, Object> val1 = new HashMap<>();
                    val1.put("name7_1", "格口数");
                    val1.put("value7_1", BigDecimalUtils.divide4(znUses, znAlls));
                    result.add(JSONObject.parseObject(JsonUtils.toJsonString(val1)));
                    Map<String, Object> val2 = new HashMap<>();
                    val2.put("name7_2", "普通货箱");
                    val2.put("value7_2", BigDecimalUtils.divide4(ptUses, ptAlls));
                    result.add(JSONObject.parseObject(JsonUtils.toJsonString(val2)));
                    Map<String, Object> val3 = new HashMap<>();
                    val3.put("name7_3", "车位");
                    val3.put("value7_3", BigDecimalUtils.divide4(carUses, carAlls));
                    result.add(JSONObject.parseObject(JsonUtils.toJsonString(val3)));
                }
                break;

            case 8:

                SysDictData wDictData = new SysDictData();
                wDictData.setDictType("wms_store_house");
                List<SysDictData> wDictDataList = iSysDictDataService.selectDictDataList(wDictData);

                if (wDictDataList != null && wDictDataList.size() > 0) {
                    List<JSONObject> finalResult = result;
                    wDictDataList.stream().forEach(item -> {

                        Map<String, Object> storeHouse = iBiService.selectCountLocatorByStoreHouse(item.getDictValue());

                        Map<String, Object> uses = new HashMap<>();
                        uses.put("y1", item.getDictLabel());
                        if (storeHouse != null && storeHouse.get("USES") != null && StringUtils.isNotEmpty(storeHouse.get("USES").toString())) {
                            uses.put("x1", Long.valueOf(storeHouse.get("USES").toString()));
                        } else {
                            uses.put("x1", 0);
                        }
                        uses.put("s1", "已使用");

                        Map<String, Object> unUses = new HashMap<>();
                        unUses.put("y1", item.getDictLabel());
                        if (storeHouse != null && storeHouse.get("UNUSES") != null && StringUtils.isNotEmpty(storeHouse.get("UNUSES").toString())) {
                            unUses.put("x1", Long.valueOf(storeHouse.get("UNUSES").toString()));
                        } else {
                            unUses.put("x1", 0);
                        }
                        unUses.put("s1", "未使用");

                        finalResult.add(JSONObject.parseObject(JsonUtils.toJsonString(uses)));
                        finalResult.add(JSONObject.parseObject(JsonUtils.toJsonString(unUses)));
                    });
                }
                break;
            //模块八
            case 9:
                Map<String, Object> cino = iBiService.selectCountInNumsOuts();
                Map<String, Object> sino = iBiService.selectCountSigns();
                Map<String, Object> inDatas = iBiService.selectBiDataOfInmus();
                Map<String, Object> outDatas = iBiService.selectBiDataOfOutmus();
                Long cinnums = 0l;
                Long cnums = 0l;
                Long coutnums = 0l;
                Long csignsnums = 0l;
                Long evidence = 0l;
                Map<String, Object> cm = new HashMap<>();
                if (cino != null) {
                    cinnums = cino.get("INNUMS") != null && StringUtils.isNotEmpty(cino.get("INNUMS").toString()) ? Long.valueOf(cino.get("INNUMS").toString()) : 0l;
                    if (cino.get("RNUMS") != null && StringUtils.isNotEmpty(cino.get("RNUMS").toString())) {
                        cinnums += Long.valueOf(cino.get("RNUMS").toString());
                    }
                    cnums = cino.get("NUMS") != null && StringUtils.isNotEmpty(cino.get("NUMS").toString()) ? Long.valueOf(cino.get("NUMS").toString()) : 0l;
                    coutnums = cino.get("OUTNUMS") != null && StringUtils.isNotEmpty(cino.get("OUTNUMS").toString()) ? Long.valueOf(cino.get("OUTNUMS").toString()) : 0l;
//                    if(cino.get("DEALS") != null && StringUtils.isNotEmpty(cino.get("DEALS").toString())){
//                        coutnums += Long.valueOf(cino.get("DEALS").toString());
//                    }
//                    if(cino.get("TUNMS") != null && StringUtils.isNotEmpty(cino.get("TUNMS").toString())){
//                        coutnums += Long.valueOf(cino.get("TUNMS").toString());
//                    }
                    csignsnums = sino.get("SIGNS") != null && StringUtils.isNotEmpty(sino.get("SIGNS").toString()) ? Long.valueOf(sino.get("SIGNS").toString()) : 0l;
                    evidence = cino.get("EOUTNUMS") != null && StringUtils.isNotEmpty(cino.get("EOUTNUMS").toString()) ? Long.valueOf(cino.get("EOUTNUMS").toString()) : 0l;
                }
                if (inDatas != null && inDatas.get("TOLS") != null && StringUtils.isNotEmpty(inDatas.get("TOLS").toString())) {
                    cnums = Long.valueOf(inDatas.get("TOLS").toString());
                }
                if (outDatas != null && outDatas.get("TOLS") != null && StringUtils.isNotEmpty(outDatas.get("TOLS").toString())) {
                    coutnums = Long.valueOf(outDatas.get("TOLS").toString());
                }
                cm.put("value8_1", evidence);//取证条数
                cm.put("value8_2", cnums);//入库条数
                cm.put("value8_3", csignsnums);//登记条数
                cm.put("value8_4", coutnums);//出库数

                result.add(JSONObject.parseObject(JsonUtils.toJsonString(cm)));

                break;
            //模块九
            case 10:
                counts = iBiService.selectCountStagings();
                List<Map<String, Object>> inons = iBiService.selectCountInNumsOutsByGroup();
                for (SysDictData dictDat : dictDataList) {
                    if (dictDat.getDictValue().equals("QB")) {
                        continue;
                    }
                    Map<String, Object> val1 = new HashMap<>();
                    Long tinnums = 0l;
                    Long tnums = 0l;
                    Long toutnums = 0l;
                    Long tsignsnums = 0l;

                    if (counts != null && counts.size() > 0) {
                        for (Map<String, Object> ct : counts) {
                            if (Objects.equals(ct.get("REGION"), dictDat.getDictValue())) {
//                                alls = ct.get("ALLS") != null && StringUtils.isNotEmpty(ct.get("ALLS").toString()) ? Long.valueOf(ct.get("ALLS").toString()) : 0l;
                                tsignsnums = ct.get("RECEIVES") != null && StringUtils.isNotEmpty(ct.get("RECEIVES").toString()) ? Long.valueOf(ct.get("RECEIVES").toString()) : 0l;
                            }
                        }
                    }

                    if (inons != null && inons.size() > 0) {
                        for (Map<String, Object> inon : inons) {
                            if (Objects.equals(inon.get("REGION"), dictDat.getDictValue())) {
                                tinnums = inon.get("INNUMS") != null && StringUtils.isNotEmpty(inon.get("INNUMS").toString()) ? Long.valueOf(inon.get("INNUMS").toString()) : 0l;
                                tnums = inon.get("NUMS") != null && StringUtils.isNotEmpty(inon.get("NUMS").toString()) ? Long.valueOf(inon.get("NUMS").toString()) : 0l;
                                toutnums = inon.get("OUTNUMS") != null && StringUtils.isNotEmpty(inon.get("OUTNUMS").toString()) ? Long.valueOf(inon.get("OUTNUMS").toString()) : 0l;
                            }
                        }
                    }
                    String region = dictDat.getDictLabel();
                    if (dictDat.getDictValue().equals("QB")) {
                        region = null;
                    } else if (dictDat.getDictValue().equals("SZ")) {
                        region = "市直";
                    } else if (dictDat.getDictValue().equals("YA")) {
                        region = dictDat.getDictLabel() + "市";
                    } else if (dictDat.getDictValue().equals("SY") || dictDat.getDictValue().equals("SX")) {
                        region = dictDat.getDictLabel() + "区";
                    } else {
                        region = dictDat.getDictLabel() + "县";
                    }
                    val1.put("name9", region);
                    val1.put("value9_1", tinnums);
                    val1.put("value9_2", tnums);
                    val1.put("value9_3", toutnums);
                    val1.put("value9_4", tsignsnums);
                    items.add(val1);
                }

                result = items.stream().map(i ->
                        JSONObject.parseObject(JsonUtils.toJsonString(i))
                ).collect(Collectors.toList());

                break;
            //模块十
            case 11:
                SysDictData dDictData = new SysDictData();
                dDictData.setDictType("deal_type");
                List<SysDictData> dDictDataList = iSysDictDataService.selectDictDataList(dDictData);
                counts = iBiService.selectCountDeal();

                for (SysDictData dictDat : dDictDataList) {
                    if (dictDat.getDictValue().equals("QB")) {
                        continue;
                    }
                    Map<String, Object> val1 = new HashMap<>();
                    Long dtotals = 0l;
                    if (counts != null && counts.size() > 0) {
                        for (Map<String, Object> ct : counts) {
                            if (Objects.equals(ct.get("TYPE"), dictDat.getDictValue())) {
                                dtotals = ct.get("TOTALS") != null && StringUtils.isNotEmpty(ct.get("TOTALS").toString()) ? Long.valueOf(ct.get("TOTALS").toString()) : 0l;
                            }
                        }
                    }

                    val1.put("name10", dictDat.getDictLabel());
                    val1.put("value10", dtotals);
                    if (dtotals != null && dtotals > 0) {
                        items.add(val1);
                    }
                }
                result = items.stream().map(i ->
                        JSONObject.parseObject(JsonUtils.toJsonString(i))
                ).collect(Collectors.toList());

                break;
            case 12:
                Map<String, Object> outs = iBiService.selectNumsOuts();
                Map<String, Object> deal = iBiService.selectNumsOutsDeal();
                Map<String, Object> val1 = new HashMap<>();
                val1.put("name10", "调用");
                val1.put("value10", 0);
                if (outs != null && outs.get("TRANNUMS") != null) {
                    val1.put("value10", outs.get("TRANNUMS"));
                    items.add(val1);
                }
                Map<String, Object> val2 = new HashMap<>();
                val2.put("name10", "处置");
                val2.put("value10", 0);
                if (deal != null && deal.get("DEALNUMS") != null) {
                    val2.put("value10", deal.get("DEALNUMS"));
                    items.add(val2);
                }
                result = items.stream().map(i ->
                        JSONObject.parseObject(JsonUtils.toJsonString(i))
                ).collect(Collectors.toList());
                break;
            case 13:
                List<Map<String, Object>> cr = new ArrayList<>();
                Map<String, Object> receiveResult = iBiService.selectReceive();

                Map<String, Object> checkReceives = new HashMap<>();
                Map<String, Object> courtReceives = new HashMap<>();
                Map<String, Object> receives = new HashMap<>();

                checkReceives.put("text", "检察院流转");
                checkReceives.put("value", receiveResult.get("CHECK_RECEIVES"));
                courtReceives.put("text", "法院流转");
                courtReceives.put("value", receiveResult.get("COURT_RECEIVES"));
                receives.put("text", "公安流转");
                receives.put("value", receiveResult.get("RECEIVES"));

                result.add(JSONObject.parseObject(JsonUtils.toJsonString(checkReceives)));
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(courtReceives)));
                result.add(JSONObject.parseObject(JsonUtils.toJsonString(receives)));
                break;
        }
        return R.ok(result);
    }

    @ApiOperation("纠正上架任务物品入库编号异常")
    @PostMapping("/updateDtl/correctQrcode")
    @Transactional(rollbackFor = Exception.class)
    public R<Void> correctQrcode(@RequestBody CabinetVo vo) {

        log.info("smartCabinet/proBatchInSmartCabine::Start");
        iPutDtlService.updatePutdtl(vo.getCno());
        log.info("smartCabinet/proBatchInSmartCabine::End");
        return R.ok();
    }

    @ApiOperation("纠正订单物品数量")
    @GetMapping("/updateTask/taskNums")
    public R<Void> taskNums() {

        log.info("smartCabinet/proBatchInSmartCabine::Start");
        iTaskService.updateTaskNums();
        log.info("smartCabinet/proBatchInSmartCabine::End");
        return R.ok();
    }

    @ApiOperation("纠正入库物品数量")
    @GetMapping("/updateWarehouse/warehouseNums")
    public R<Void> warehouseNums() {

        log.info("warehouseNums::Start");
        iTaskService.updateWarehouseNums();
        log.info("warehouseNums::End");
        return R.ok();
    }

    @ApiOperation("纠正订单物品数量")
    @GetMapping("/updateOrder/updateOrderWithWaybill")
    public R<Void> updateOrderWithWaybill() {

        log.info("smartCabinet/proBatchInSmartCabine::Start");
        iTaskService.updateOrderWithWaybill();
        log.info("smartCabinet/proBatchInSmartCabine::End");
        return R.ok();
    }

    @ApiOperation("纠正车辆外观图片")
    @GetMapping("/updatePics/{taskNo}")
    public R<Void> updatePics(@ApiParam("数据类型")
                              @NotNull(message = "数据类型不能为空")
                              @PathVariable("taskNo") String taskNo) {

        log.info("smartCabinet/proBatchInSmartCabine::Start");
        iTaskService.updatePics(taskNo);
        log.info("smartCabinet/proBatchInSmartCabine::End");
        return R.ok();
    }

    @ApiOperation("纠正交接附件异常")
    @GetMapping("/updateHandoverFile")
    public R<Void> updateHandoverFile() {

        log.info("smartCabinet/updateHandoverFile::Start");
        iTaskService.updateHandoverFile();
        log.info("smartCabinet/updateHandoverFile::End");
        return R.ok();
    }

    @ApiOperation("验证推送")
    @GetMapping("/validPush/{cid}")
    public R<ApiResult<Map<String, Map<String, String>>>> validPush(@ApiParam("数据类型")
                                                                    @NotNull(message = "数据类型不能为空")
                                                                    @PathVariable("cid") String cid) {

        log.info("validPush::Start");
//        PushUtils.pushTest(cid);
        aliyunSmsService.testSendSMS();
        log.info("validPush::End");
        return R.ok();
    }

    @ApiOperation("智能柜货架修改")
    @GetMapping("/updateCabinets")
    public R<ApiResult<Map<String, Map<String, String>>>> updateCabinets() {

        iLocatorService.autoUpdateDZCabinetGroup();
        return R.ok();
    }

    @ApiOperation("库存数据修正")
    @GetMapping("/reCheckInventoryDatas")
    public R<List<InventoryVo>> reCheckInventoryDatas() {

        return R.ok(iInventoryService.reCheckInventoryDatas());
    }

    @ApiOperation("数据重推")
    @GetMapping("/rePushDatas/{api}")
    public R<Void> rePushDatas(@ApiParam("数据类型")
                               @NotNull(message = "数据类型不能为空")
                               @PathVariable("api") String api) {

        switch (api) {
            case "proBase"://物品日志
                PropertyLogBo propertyLogBo = new PropertyLogBo();
                propertyLogBo.setDelFlag("0");
                List<PropertyLogVo> loglist = iPropertyLogService.queryList(propertyLogBo);
                if (loglist != null && loglist.size() > 0) {
                    for (PropertyLogVo logVo : loglist) {
                        PropertyLogModelsVo data = new PropertyLogModelsVo();
                        data.setApi("proBase");
                        data.setData(logVo);
                        PushDatasUtil.pushPropertyDatas(data);
                    }
                }
                break;
            case "proManage"://接收登记
                Integer counts = 0;
                StagingBo stagingBo = new StagingBo();
                stagingBo.setDelFlag("0");
                stagingBo.setTransferStatus("2");
                List<Staging> stagingList = iStagingService.listStaging(stagingBo);
                List<StagingDatasVo> datas = new ArrayList<>();
                log.info("stagingListCounts:" + stagingList.size());
                if (stagingList != null && stagingList.size() > 0) {
                    for (Staging staging : stagingList) {
//                        if(StringUtils.isEmpty(staging.getType())){
//                            continue;
//                        }
                        PropertyVo property = iPropertyService.queryByNo(staging.getPno());
                        if (property != null) {
                            SysOssBo ossBo = new SysOssBo();
                            ossBo.setBuss("property");
                            ossBo.setObjid(property.getPno());
                            List<SysOss> oss = iSysOssService.selectSysOssList(ossBo);
                            datas.add(pushDatas(staging, property, oss));
                            counts++;
                        }
                    }
                }
                log.info("StagingDatasVo:" + datas.size());
                log.info("proManageCounts:" + counts);
                PushDatasUtil.pushProManage(datas);
                break;
            case "putTask"://上架任务
                PutTaskBo putTaskBo = new PutTaskBo();
                List<PutTaskVo> taskVos = iPutTaskService.queryList(putTaskBo);
                if (taskVos != null && taskVos.size() > 0) {
                    for (PutTaskVo taskVo : taskVos) {
                        iPutTaskService.pushPutTaskDatas(taskVo.getId());
                    }
                }
                break;
            case "inWarehouse"://入库单推送
                TaskBo taskBo = new TaskBo();
                taskBo.setDelFlag("0");
                List<TaskVo> taskVoList = iTaskService.queryList(taskBo);
                if (taskVoList != null && taskVoList.size() > 0) {
                    for (TaskVo taskVo : taskVoList) {
                        InTaskDatasVo data = BeanUtil.toBean(taskVo, InTaskDatasVo.class);
                        OperatorLogBo opBo = new OperatorLogBo();
                        opBo.setObjid(taskVo.getId());
                        List<OperatorLogVo> oplogs = iOperatorLogService.queryList(opBo);
                        TaskDtlBo dtlBo = new TaskDtlBo();
                        dtlBo.setTaskId(taskVo.getId());
                        List<TaskDtlVo> dtls = iTaskDtlService.queryList(dtlBo);
                        List<InTaskDatasDtlVo> items = dtls.stream().map(item -> {
                            InTaskDatasDtlVo dvo = BeanUtil.copyProperties(item, InTaskDatasDtlVo.class);
                            return dvo;
                        }).collect(Collectors.toList());
                        data.setItems(items);
                        data.setLogs(oplogs);
                        PushDatasUtil.pushInTaskDatas(data);
                    }
                }
                break;
            case "logistics"://TMS订单
                OrderBo orderBo = new OrderBo();
                orderBo.setDelFlag("0");
                List<OrderVo> orderVos = iOrderService.queryList(orderBo);
                if (orderVos != null && orderVos.size() > 0) {
                    for (OrderVo orderVo : orderVos) {
                        iCommonService.orderPush(orderVo.getId());
                    }
                }
                break;
            case "handoverSigns"://交接签名
                HandoverBo handoverBo = new HandoverBo();
                handoverBo.setStatus("1");
                List<HandoverVo> handoverVos = iHandoverService.queryList(handoverBo);
                if (handoverVos != null && handoverVos.size() > 0) {
                    for (HandoverVo handoverVo : handoverVos) {
                        iCommonService.autographPush(handoverVo.getId());
                    }
                }
                break;
        }
        return R.ok();
    }

    public StagingDatasVo pushDatas(Staging enty, PropertyVo property, List<SysOss> oss) {

        StagingDatasVo data = new StagingDatasVo();
        BeanUtil.copyProperties(property, data);
        data.setWpbh(property.getPno());
        data.setProname(property.getName());
        StagingVo vo = iStagingService.queryById(enty.getId());

        if (enty.getDeptId() != null) {
            SysDept dept = iSysDeptService.selectDeptById(enty.getDeptId());
            data.setDeptNo(dept.getDeptCode());
            data.setDeptName(dept.getDeptName());
            data.setUndertaker(dept.getDeptCode());
        }

        if (property.getBelongDeptId() != null) {
            SysDept dept = iSysDeptService.selectDeptById(property.getBelongDeptId());
            data.setBelongofficeid(dept.getDeptCode());
        }

        if (property.getOfficeId() != null) {
            SysDept dept = iSysDeptService.selectDeptById(property.getOfficeId());
            data.setOfficeid(dept.getDeptCode());
        }
        if (enty.getStoreId() != null) {
            StoreVo store = iStoreService.queryById(enty.getStoreId());
            data.setCustodianplace(store.getName());
        }
        data.setPronum(enty.getNums());
        data.setReceiveNums(enty.getReceiveNums());
        data.setUnit(enty.getUnit());

        if (!StringUtils.isEmpty(property.getClassifyId())) {
            ClassifyVo classify = iClassifyService.queryById(property.getClassifyId());
            data.setProcategory(classify.getClassifyNo());
        }

        if (!StringUtils.isEmpty(property.getSecondClassifyId())) {
            ClassifyVo classify = iClassifyService.queryById(property.getSecondClassifyId());
            data.setSeccategory(classify.getClassifyNo());
        }

        if (!StringUtils.isEmpty(property.getThirdClassifyId())) {
            ClassifyVo classify = iClassifyService.queryById(property.getThirdClassifyId());
            data.setThirdcategory(classify.getClassifyNo());
        }

        data.setType(enty.getType());
        data.setRegisterTime(enty.getRegisterTime());
        data.setRemark(enty.getRemark());
        data.setRegisterer(enty.getRegisterer() == null ? vo.getUpdateName() : enty.getRegisterer());
        data.setFeature(enty.getFeature());
        data.setCreatedate(enty.getCreateTime());
        data.setUpdatedate(enty.getUpdateTime());
        data.setPersonname(enty.getRegisterer() == null ? vo.getUpdateName() : enty.getRegisterer());
        data.setOss(oss);
        data.setDelflag(enty.getDelFlag() != null ? Integer.valueOf(enty.getDelFlag()) : 0);
        PropertyLogBo logBo = new PropertyLogBo();
        logBo.setPno(enty.getPno());
        data.setLogs(iPropertyLogService.queryList(logBo));
//        PushDatasUtil.pushStagingDatas(data);
        return data;
    }


    @GetMapping("/unReplace")
    @Transactional(rollbackFor = Exception.class)
    public void unReplace() {

        List<Task> taskList = taskDtlService.getAllRePlaceTask();
        String[] ignoreProperties = {"id"};
        taskList.forEach(item -> {
            Task task1 = new Task();
            BeanUtil.copyProperties(item, task1, ignoreProperties);
            Task task = new Task();
            BeanUtil.copyProperties(item, task, ignoreProperties);
            //设置处置单子的订单号
            task.setTaskNo(task1.getTaskNo());
            task.setReplaceNo(task1.getReplaceNo());
            task.setType("2");
            task.setReturnId(task1.getId());

            //保存处置单子
            if (taskService.insert(task) == 0) {
                throw new ServiceException("保存订单失败");
            }

            //设置订单号
            item.setTaskNo(item.getReplaceNo());
            //设置调用单子
            item.setType("3");
            item.setReplaceNo("");
            //保存处置单子
            if (taskService.updateById(item) == 0) {
                throw new ServiceException("保存订单失败");
            }

            List<TaskDtl> taskDtls = taskDtlService.selectList(new LambdaQueryWrapper<TaskDtl>().eq(TaskDtl::getTaskId, item.getId()).eq(TaskDtl::getDelFlag, 0));

            List<TaskDtl> dtls = taskDtls.stream().map(dtli -> {
                TaskDtl dtl = new TaskDtl();
                BeanUtil.copyProperties(dtli, dtl, ignoreProperties);
                dtl.setTaskId(task.getId());
                return dtl;
            }).collect(Collectors.toList());

            if (!taskDtlService.insertBatch(dtls)) {
                throw new ServiceException("保存订单财物失败");
            }

            TaskDisposalInfo disposalInfo = taskDisposalInfoMapper.getDisposalInfo(item.getId());
            if (disposalInfo != null) {
                disposalInfo.setTaskId(task.getId());
                taskDisposalInfoMapper.updateById(disposalInfo);
            }

            /**
             * 如果已下发，更新对应清单
             */
            //出库单
            ExWarehouse exWarehouse = exWarehouseMapper.selectExWarehouseByTaskId(item.getId());
            if (exWarehouse != null) {
                exWarehouse.setExno(item.getTaskNo());
                exWarehouse.setReplaceNo("");
                exWarehouseMapper.updateById(exWarehouse);
            }

            //订单
            Order order = orderMapper.selectOrderByID(item.getId());
            if (order != null) {
                order.setOrderNo(item.getTaskNo());
                order.setType(item.getType());
                orderMapper.updateById(order);
            }
        });

    }

}
